package com.ruoyi.exhibition.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.art.dto.Result;
import com.ruoyi.artworks.domain.Artworks;
import com.ruoyi.course.domain.CourseCla;
import com.ruoyi.exhibition.dao.ClaStuDao;
import com.ruoyi.exhibition.domain.ExhiForm;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exhibition.domain.Exhibition;
import com.ruoyi.exhibition.service.IExhibitionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投票管理Controller
 * 
 * @author hyl
 * @date 2025-06-20
 */
@RestController
@RequestMapping("/exhibition/exhibition")
public class ExhibitionController extends BaseController
{
    @Autowired
    private IExhibitionService exhibitionService;

    /**
     * 查询投票管理列表
     */
    @PreAuthorize("@ss.hasPermi('exhibition:exhibition:list')")
    @GetMapping("/list")
    public TableDataInfo list(Exhibition exhibition)
    {
        startPage();
        List<Exhibition> list = exhibitionService.selectExhibitionList(exhibition);
        return getDataTable(list);
    }

    /**
     * 导出投票管理列表
     */
    @PreAuthorize("@ss.hasPermi('exhibition:exhibition:export')")
    @Log(title = "投票管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Exhibition exhibition)
    {
        List<Exhibition> list = exhibitionService.selectExhibitionList(exhibition);
        ExcelUtil<Exhibition> util = new ExcelUtil<Exhibition>(Exhibition.class);
        util.exportExcel(response, list, "投票管理数据");
    }

    /**
     * 获取投票管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('exhibition:exhibition:query')")
    @GetMapping(value = "/{exhId}")
    public AjaxResult getInfo(@PathVariable("exhId") Long exhId)
    {
        return success(exhibitionService.selectExhibitionByExhId(exhId));
    }

    /**
     * 新增投票管理
     */
    @PreAuthorize("@ss.hasPermi('exhibition:exhibition:add')")
    @Log(title = "投票管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Exhibition exhibition)
    {
        return toAjax(exhibitionService.insertExhibition(exhibition));
    }

    /**
     * 修改投票管理
     */
    @PreAuthorize("@ss.hasPermi('exhibition:exhibition:edit')")
    @Log(title = "投票管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Exhibition exhibition)
    {
        return toAjax(exhibitionService.updateExhibition(exhibition));
    }

    /**
     * 删除投票管理
     */
    @PreAuthorize("@ss.hasPermi('exhibition:exhibition:remove')")
    @Log(title = "投票管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{exhIds}")
    public AjaxResult remove(@PathVariable Long[] exhIds)
    {
        return toAjax(exhibitionService.deleteExhibitionByExhIds(exhIds));
    }

//    根据校区Id查询所有班级
    @GetMapping("/selectAllClass")
    public AjaxResult selectAllClass(CourseCla courseCla){
        List<CourseCla> classList = exhibitionService.selectAllClass(courseCla);
        return AjaxResult.success("classList",classList);
    }

//    通过班级Id查询学生
    @GetMapping("/selectAllStudent")
        public AjaxResult selectAllStudent(ClaStuDao claStuDao){
        List<ClaStuDao> studentList = exhibitionService.selectAllStudent(claStuDao);
        return AjaxResult.success("studentList",studentList);
    }

//    通过学生查询作品
    @GetMapping("/selectAllWorks")
    public AjaxResult selectAllWorks(Artworks artworks){
        List<Artworks> artworksList = exhibitionService.selectAllWorks(artworks);
        return AjaxResult.success("artworksList",artworksList);
    }

//    提交投票作品
    @PostMapping("/insertWorks")
    public AjaxResult insertWorks(@RequestBody List<ExhiForm> exhiForm){
        System.out.println(exhiForm+"张和桓，，，，，，闹啦");
        return success(exhibitionService.insertWorks(exhiForm));
    }
}
